package cn.supermaster.management.web.controller.monitor;

import cn.supermaster.management.web.service.monitor.IMonitorCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.supermaster.management.common.controller.BaseController;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 缓存监控
 */
@Controller
@RequestMapping("/monitor/cache")
public class MonitorCacheController extends BaseController {

    @Autowired
    IMonitorCacheService monitorCacheService;

    @GetMapping()
    public String cache(ModelMap modelMap) {
        return monitorCacheService.queryAllCacheNames(modelMap);
    }

    @RequestMapping(value = "/getNames", method = RequestMethod.POST)
    public String getCacheNames(String fragment, ModelMap modelMap) {
        return monitorCacheService.queryCacheNames(modelMap, fragment);
    }

    @RequestMapping(value = "/getKeys", method = RequestMethod.POST)
    public String getCacheKeys(String fragment, String cacheName, ModelMap modelMap) {
        return monitorCacheService.queryCacheKeys(modelMap, fragment, cacheName);
    }

    @RequestMapping(value = "/getValue", method = RequestMethod.POST)
    public String getCacheValue(String fragment, String cacheName, String cacheKey, ModelMap modelMap) {
        return monitorCacheService.queryCacheValue(modelMap, fragment, cacheName, cacheKey);
    }
}
